# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models


class Article (models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    picture = models.URLField()
    picture_title = models.CharField(max_length=50, default='')
    status = models.SmallIntegerField(default=0)  # -2 审核不通过 -1 已删除 0 待发布 1 已发布  2 待审核 ...
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    user = models.ForeignKey('userModel.User', on_delete=models.CASCADE)

    class Meta:
        db_table = 'article'

    def get_status_str(self):
        obj = {
            -2: "审核不通过",
            -1: '已删除',
            0: '待发布',
            1: '已发布',
            2: '待审核'
        }
        return obj[self.status]


class ArticleLikeUser (models.Model):
    article = models.ForeignKey('Article', on_delete=models.CASCADE)
    user = models.ForeignKey('userModel.User', on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'article_like_user'


